#! /usr/bin/env bash
# Copyright (c) 2016 - 2019 DisplayLink (UK) Ltd.

set -e
set -u

files=(
  checkpatch.pl
  const_structs.checkpatch
  spelling.txt
)

for file in ${files[@]}; do
  wget -N -q "https://raw.githubusercontent.com/torvalds/linux/master/scripts/${file}"
done

chmod +x checkpatch.pl

set +e

result=0
./checkpatch.pl --terse --no-tree --ignore NEW_TYPEDEFS -f ./library/*
result=$((result || $?))

./checkpatch.pl --terse --no-tree --ignore LINUX_VERSION_CODE,PREFER_PR_LEVEL -f ./module/*
result=$((result || $?))

rm ${files[@]}

exit ${result}
